package org.redr.widgetGUI.core;

import java.io.File;

import org.redr.canvas.OSPath;
import org.redr.canvas.RedRApplication;
import org.redr.widgetGUI.settings.WidgetSettings;
import org.redr.widgetGUI.settings.WidgetState;
import org.redr.widgetGUI.settings.settingsTools.ItemsHandler;

import com.trolltech.qt.gui.QIcon;
import com.trolltech.qt.gui.QPushButton;

public class CommitButton extends WidgetState {
	
	WidgetBox checkBoxArea;
	CheckBox processOnChange;
	Button button;
	
	public QPushButton widget(){
		return button.widget();
	}
	
	
	
	public CommitButton(LayoutState parent, WidgetSettings ws) {
		super(parent, ws);
		checkBoxArea = new WidgetBox(parent, ws.getSettings("checkBoxArea"));
		ItemsHandler processOnChangeItemsButtons = ws.getSettings("checkBoxArea").getSettings("processOnChange").items("buttons");
		processOnChangeItemsButtons.setDefaultItem("poc", _("Process On Parameter Change"));
		processOnChangeItemsButtons.setDefaultItem("poi", _("Process On Data Input"));
		
		ItemsHandler processOnChangeItemsToolTips = ws.getSettings("checkBoxArea").getSettings("processOnChange").items("toolTip");
		processOnChangeItemsToolTips.setDefaultItem("poc", _("Try to process as soon as a parameter is changed."));
		processOnChangeItemsToolTips.setDefaultItem("poi", _("Try to process as soon as data is received by the widget. The current state of parameters will be applied."));
		
		ItemsHandler processOnChangeItemsChecked = ws.getSettings("checkBoxArea").getSettings("processOnChange").items("checked");
		processOnChangeItemsChecked.setDefaultItem("poc", "checked");
		processOnChangeItemsChecked.setDefaultItem("poi", "checked");
		
		processOnChange = new CheckBox(checkBoxArea, (WidgetSettings) ws.getSettings("checkBoxArea").getSettings("processOnChange").setDefault("label", "Process On Change"));
		parent.addWidget(processOnChange);
		button = new Button(this.layout, (WidgetSettings) ws.getSettings("button").setDefault("label", "Commit"));
		
		File iconFile = OSPath.join(RedRApplication.parentDir, "coreIcons", "fork.png");
		
		button.widget().setIcon(new QIcon(iconFile.toString()));
		parent.addWidget(button);
		
	}



	public boolean processOnInput() {
		// TODO Auto-generated method stub
		return processOnChange.checkedButtons().contains("poc");
	}

}
